package com.mt.mtyx.common.exception;

import com.mt.mtyx.common.result.ResultCodeEnum;
import lombok.Data;

/**
 * 自定义业务异常类
 *
 * @author WMT
 * @Date 2023/6/12 15:30
 */
@Data
public class BusinessException extends RuntimeException {

    /**
     * 异常状态码
     */
    private Integer code;

    /**
     * 通过状态码和错误消息创建异常对象
     *
     * @param message 错误信息
     * @param code    异常状态码
     */
    public BusinessException(String message, Integer code) {
        super(message);
        this.code = code;
    }

    /**
     * 接收枚举类型对象
     *
     * @param resultCodeEnum 状态信息枚举
     */
    public BusinessException(ResultCodeEnum resultCodeEnum) {
        super(resultCodeEnum.getMessage());
        this.code = resultCodeEnum.getCode();
    }
}
